package com.candy.databasedocuments.utils;

import java.sql.*;

/**
 * @author suYanLong
 * @version 1.0
 * @date 2023/7/5 14:48
 * @Description 描述
 */
public class JdbcConnectUtil {

    public static Connection getConnect(String driver, String url, String username, String password) throws Exception {
        Class.forName(driver);
        //获取连接
        return DriverManager.getConnection(url, username, password);
    }

    public static void closeResources(Connection connection, Statement statement, ResultSet resultSet) {
        //释放资源
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException sqlException) {
                sqlException.printStackTrace();
            }
        }
        if (statement != null) {
            try {
                statement.close();
            } catch (SQLException sqlException) {
                sqlException.printStackTrace();
            }
        }
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException sqlException) {
                sqlException.printStackTrace();
            }
        }
    }

}
